package nirvana.core.utils.ids;

import cn.hutool.core.util.IdUtil;

/**
 * ID器生成接口
 *
 * @param <T> ID 数据类型
 */
@FunctionalInterface
public interface IdGenerator<T> {
    /**
     * generate id
     * lambda interface only have one function need to be implemented
     *
     * @return id
     */
    T generate();


    /**
     * 生成 UUID
     */
    IdGenerator<String> UUID = IdUtil::randomUUID;


    /**
     * 生成雪花 ID
     */
    IdGenerator<Long> SNOW = IdUtil.getSnowflake (IdWorkerUtils.getWorkId (), IdWorkerUtils.getDataCenterId ())::nextId;
}
